<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>发布商品</title>
    <!--字体图标cdn-->
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

    <!--主体区域结束-->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js"></script>

    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <style type="text/css">
        body {
            background-color: #2e2e2e;
            padding-top: 20px;
            color: #ffc600;
        }
        .navbar{
            background-color: black;
            border: none;
        }
        h3{
            color: #ffc600;
            position: absolute;
            left: 43%;
            top: -7px;
        }

        #back{
            color: #ffc600;
            position: relative;
            left: -10px;
        }
    </style>

</head>
<body>
<header>
    <div class="container">
        <nav class="navbar navbar-default">
            <div class="navbar-header">
                <div class="logo">
                    <a href="/index.html"> <img style="margin:5px 10px;width: 100px;height: 45px;" src="https://upyun.dinghuale.com/uploads/images/logo.png" alt=""></a>
                </div>
            </div>
            <h3 >发布商品</h3>
            <ul class="nav navbar-nav navbar-right">
                <li><a id="back"
                       href="/index.html">返回首页</a></li>
            </ul>
        </nav>
    </div>
</header>

<div class="container">
    <div class="row">
        <!--左侧主要内容-->
        <div class="col-md-offset-2 col-md-8">
            <div class="bs-docs-section">
                <form id="myform" method="post"
                      enctype="multipart/form-data">
                    <div class="form-group">
                        <label   for="title">花名主题</label> <input type="text"
                                                               class="form-control" id="title" name="title"
                                                               placeholder="请输入花名主题">
                    </div>
                    <div class="form-group">
                        <label for="aabstract">价格</label> <input type="text"
                                                                   class="form-control" id="aabstract" name="price"
                                                                   placeholder="请输入价格">
                    </div>
                    <div class="form-group">
                        <label for="nick">分类名称</label> <input type="text"
                                                                 class="form-control" id="nick" name="name"
                                                                 placeholder="请输入分类名称">
                    </div>
                    <div class="form-group">
                        <label for="intro">商品简介</label>
                        <textarea  class="form-control" rows="4" id="intro"
                                   name="intro" >无详细介绍</textarea>
                    </div>
                    <div class="form-group">
                        <label >选择分类</label>
                        <select   name="categoryId">
                            <option v-for="c in c_arr" :value="c.id">{{c.name}}</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputFile">选择文件</label>
                        <input type="file" id="exampleInputFile" name="file">
                    </div>
                    <div class="text-center">
                        <button type="button" class="btn btn-danger btn-lg "
                                @click="upload()" >发布商品</button>
                    </div>
                </form>
            </div>
        </div>
        <!--左侧内容结束-->
    </div>
</div>
<!--网页底部-->
<footer class="well container">
    <b>
        <a href="http://www.tedu.cn/">李伟峰时代文化创意工作室</a>
    </b> <span class="pull-right"> <b>Version</b> 0.1.0
			</span>
</footer>

<script>
    let v = new Vue({
        el:"form",
        data:{
            c_arr:[]
        },
        created:function () {
            //请求所有分类信息
            axios.get("/category/select").then(function (response) {
                v.c_arr = response.data;
            })
        },
        methods:{
            upload:function () {
                //得到form表单的数据
                let data = new FormData(document.querySelector("form"));
                //判断是否选择了文件
                if (data.get("file").name==""){
                    alert("请选择上传的文件!");
                    return;
                }
                //发请求
                axios.post("/product/insert",data).then(function (response) {
                    alert("发布成功!");
                    location.href="/admin-product.html";//显示作品管理页面
                })
            }
        }
    })
</script>
</body>
</html>